package com.dlc.shop.systemtest.data.amount;

import com.dlc.shop.bean.model.Category;
import com.dlc.shop.bean.model.CategoryLang;
import com.dlc.shop.bean.model.CategoryShop;
import com.dlc.shop.bean.vo.CategoryShopVO;
import com.dlc.shop.systemtest.api.amount.CategoryApi;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author lanhai
 */
public class CategoryData {
    public static Category getCategory(String name, Double deductionRate){
        Category category = new Category();
        CategoryLang categoryLang = new CategoryLang();
        categoryLang.setLang(0);
        categoryLang.setCategoryId(0L);
        categoryLang.setCategoryName(name);
        category.setCategoryLangList(Arrays.asList(categoryLang));
        category.setDeductionRate(deductionRate);
        category.setGrade(2);
        category.setParentId(276L);
        category.setPic("2023/03/9f1f9e7cc1b5487a979814f976858d65.gif");
        category.setSeq(1);
        category.setStatus(1);
        return category;
    }

    public static CategoryShop getCategoryShop(Long categoryId, Double deductionRate){
        CategoryShop categoryShop = new CategoryShop();
        categoryShop.setCategoryId(categoryId);
        categoryShop.setRate(deductionRate);
        return categoryShop;
    }

    public static Category getCategory(Long categoryId, Integer grade, Long parentId, Integer status, Double deductionRate, String categoryName){
        Category category = new Category();
        category.setCategoryId(Objects.isNull(categoryId) ? null : categoryId);
        category.setGrade(grade);
        category.setParentId(parentId);
        category.setPic("/pic.png");
        category.setSeq(1);
        category.setStatus(status);
        category.setDeductionRate(deductionRate);

        List<CategoryLang> categoryLangList = new ArrayList<>();
        CategoryLang categoryLang = new CategoryLang();
        categoryLang.setCategoryId(0L);
        categoryLang.setCategoryName(categoryName);
        categoryLang.setLang(0);
        categoryLangList.add(categoryLang);

        category.setCategoryLangList(categoryLangList);

        return category;
    }

    public static Category getShopCategory(Long categoryId, Integer grade, Long parentId, Integer status, String shopCategoryName){
        Category shopCategory = new Category();
        shopCategory.setCategoryId(Objects.isNull(categoryId) ? null : categoryId);
        shopCategory.setGrade(grade);
        shopCategory.setParentId(parentId);
        shopCategory.setSeq(1);
        shopCategory.setStatus(status);

        List<CategoryLang> shopCategoryLangList = new ArrayList<>();
        CategoryLang shopCategoryLang = new CategoryLang();
        shopCategoryLang.setCategoryId(0L);
        shopCategoryLang.setCategoryName(shopCategoryName);
        shopCategoryLang.setLang(0);
        shopCategoryLangList.add(shopCategoryLang);
        shopCategory.setCategoryLangList(shopCategoryLangList);


        return shopCategory;
    }

    public static Double getCategoryRate(Long categoryId) {
        List<CategoryShopVO> categoryShopVOList = CategoryApi.listSigningCategory();
        Double categoryRate = 0.0;
        for (CategoryShopVO categoryShopVO : categoryShopVOList) {
            if (categoryShopVO.getCategoryId().equals(categoryId)) {
                categoryRate = Objects.isNull(categoryShopVO.getCustomizeRate()) ? categoryShopVO.getPlatformRate() : categoryShopVO.getCustomizeRate();
            }
        }
        return categoryRate;
    }
}
